﻿using System.Web;
using System.Web.Compilation;
using System.Web.Mvc;
using UIShell.OSGi;
using UIShell.OSGI.Mvc;

[assembly: PreApplicationStartMethod(typeof(BundleRuntimeMvcApplication), "BundleStart")]
namespace UIShell.OSGI.Mvc
{
    public class BundleRuntimeMvcApplication : HttpApplication
    {
        public static void BundleStart()
        {
            var runtime = new BundleRuntime();
            runtime.Start();
            runtime.InvokeAddReferencedAssembly(BuildManager.AddReferencedAssembly);
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            ControllerBuilder.Current.SetControllerFactory(new BundleRuntimeControllerFactory());

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new BundleRuntimeViewEngine());

            OnApplication_Start();
        }

        protected virtual void OnApplication_Start()
        {

        }
    }
}
